package com.zhongkai.controller;

import com.zhongkai.app.service.IndentService;
import com.zhongkai.model.utils.TTHelp;
import com.zhongkai.model.utils.ZhongkaiResult;
import com.zhongkai.model3.Chinaset;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


/**
 * 采购申请
 */
@Controller
public class IndentController {

    @Autowired
    private IndentService indentService;

    /**
     * 新增采购信息
     *
     * @param name        商品名称
     * @param product_uuid 商品uuid
     * @param ind_price   单价
     * @param ind_count   数量
     * @param ind_sum     总金额
     * @param vender_name 厂家名称
     * @param ind_vender  厂家id
     */
    @RequestMapping(value = "/indent_service/add", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult addIndentService(String name,String product_uuid,
                                           String ind_price, String ind_count, String ind_sum,
                                           String vender_name, String ind_vender,
                                           HttpServletRequest httpServletRequest
    ) {

        String uuid = TTHelp.generate();

        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");

        ZhongkaiResult result = indentService.addIndentService(uuid, name,product_uuid,
                ind_price, ind_count, ind_sum, vender_name, ind_vender, chinaset.getSetName(), chinaset.getUuid());

        return result;
    }


    /**
     * 修改采购信息
     *
     * @param id          唯一标识
     * @param name        商品名称
     * @param product_uuid 商品uuid
     * @param ind_price   单价
     * @param ind_count   数量
     * @param ind_sum     总金额
     * @param vender_name 厂家名称
     * @param ind_vender  厂家id
     */
    @RequestMapping(value = "/indent_service/update", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult updateIndentService(@RequestParam(defaultValue = "0") Long id, String name, String product_uuid,String ind_price, String ind_count, String ind_sum,
                                              String vender_name, String ind_vender, String ind_person, String person_uuid, HttpServletRequest httpServletRequest
    ) {

        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
        ZhongkaiResult result = indentService.updateIndentService(id, name,product_uuid,
                ind_price, ind_count, ind_sum, vender_name, ind_vender, chinaset.getSetName(), chinaset.getUuid());

        return result;
    }

    /**
     * 删除采购信息
     *
     * @param id id
     */
    @RequestMapping(value = "/indent_service/remove", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult removeIndentService(@RequestParam(defaultValue = "0") Long id
    ) {


        ZhongkaiResult result = indentService.removeIndentService(id);

        return result;
    }


    /**
     * 列表
     *
     * @param page 页码
     * @param rows 条数
     */
    @RequestMapping(value = "/indent_service/list", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult listIndentService(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer rows
    ) {


        ZhongkaiResult result = indentService.listIndentService(page, rows);

        return result;
    }


    //---------------------------------------办公采购-------------------------------------------------------------

    /**
     * 新增采购信息
     *
     * @param name        商品名称
     * @param product_uuid 商品uuid
     * @param ind_price   单价
     * @param ind_count   数量
     * @param ind_sum     总金额
     * @param vender_name 厂家名称
     * @param ind_vender  厂家id
     */
    @RequestMapping(value = "/indent_service/add2", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult addIndentService2(String name,String product_uuid,
                                            String ind_price, String ind_count, String ind_sum,
                                            String vender_name, String ind_vender, HttpServletRequest httpServletRequest
    ) {


        String uuid = TTHelp.generate();

        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
        ZhongkaiResult result = indentService.addIndentService2(uuid, name,product_uuid,
                ind_price, ind_count, ind_sum, vender_name, ind_vender, chinaset.getSetName(), chinaset.getUuid());

        return result;
    }


    /**
     * 修改采购信息
     *
     * @param id          唯一标识
     * @param name        商品名称
     * @param product_uuid 商品uuid
     * @param ind_price   单价
     * @param ind_count   数量
     * @param ind_sum     总金额
     * @param vender_name 厂家名称
     * @param ind_vender  厂家id
     */
    @RequestMapping(value = "/indent_service/update2", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult updateIndentService2(@RequestParam(defaultValue = "0") Long id, String name, String product_uuid,String ind_price, String ind_count, String ind_sum,
                                               String vender_name, String ind_vender, String ind_person, String person_uuid, HttpServletRequest httpServletRequest
    ) {

        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
        ZhongkaiResult result = indentService.updateIndentService2(id, name,product_uuid,
                ind_price, ind_count, ind_sum, vender_name, ind_vender, chinaset.getSetName(), chinaset.getUuid());

        return result;
    }

    /**
     * 删除采购信息
     *
     * @param id id
     */
    @RequestMapping(value = "/indent_service/remove2", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult removeIndentService2(@RequestParam(defaultValue = "0") Long id
    ) {


        ZhongkaiResult result = indentService.removeIndentService2(id);

        return result;
    }


    /**
     * 采购信息列表
     */
    @RequestMapping(value = "/indent_service/list2", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult listIndentService2(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer rows
    ) {


        ZhongkaiResult result = indentService.listIndentService2(page, rows);

        return result;
    }
}
